function [position_legend,rNormal,rBuy,rSell,nTrading,r_excess_after_cost] = testTRB(price_path,risk_free,cost,short_MA_length,long_MA_length,band,option,day_minmax)   
    price_min = NaN(length(price_path)-day_minmax,1);
    price_max = price_min;

    rNormal = log(price_path(2:end)./price_path(1:end-1));
    day_lag = 3;
    price_path = price_path';

    rBuy = NaN(length(price_path),1);
    rSell = NaN(length(price_path),1);
    buy = 0;
    sell = 0;
    nTrading = 0;
    flag_get_buy_stock = 0;
    flag_get_sell_stock = 0;
    
    for i = day_minmax+1:length(price_path) - day_lag
        price_min(i) = min(price_path(i-day_minmax:i-1));
        price_max(i) = max(price_path(i-day_minmax:i-1));
    end
    %plot the result
    hold on
    h1 = plot(price_path);
    h2 = plot(price_max,'r');
    h3 = plot(price_min,'g');
%     axis([100 300 10 25])
%     grid on

    for i = day_minmax+1:length(price_path) - day_lag
%         price_min(i) = min(price_path(i-day_minmax:i-1));
%         price_max(i) = max(price_path(i-day_minmax:i-1));
        if price_path(i) >= (1+band)*price_max(i)
            rBuy(i+day_lag) = log(price_path(i+day_lag)/price_path(i+day_lag-1)) - risk_free;
            buy = 1;
            if flag_get_buy_stock == 0
                h6 = plot(i+day_lag,price_path(i+day_lag),'s','MarkerEdgeColor','k',...
                    'MarkerFaceColor','m','MarkerSize',12);
                flag_get_buy_stock = 1;               
                flag_get_sell_stock = 0;
                last_buy_day = i;
            end
            h4 = plot(i,price_path(i),'o','MarkerEdgeColor','k',...
                 'MarkerFaceColor','r','MarkerSize',6);
        elseif price_path(i) <= (1-band)*price_min(i)
            rSell(i+day_lag) = risk_free - log(price_path(i+day_lag)/price_path(i+day_lag-1));
            sell = 1;
            if flag_get_sell_stock == 0 && flag_get_buy_stock == 1 && i-last_buy_day>=3
                h7 = plot(i,price_path(i),'s','MarkerEdgeColor','k',...
                 'MarkerFaceColor','c','MarkerSize',12);
                flag_get_buy_stock = 0;
                flag_get_sell_stock = 1;
            end
            h5 = plot(i,price_path(i),'o','MarkerEdgeColor','k',...
                 'MarkerFaceColor','g','MarkerSize',6);
        end
        if buy == 1 && sell == 1
            h8 = plot(i,price_path(i),'o','MarkerEdgeColor','k',...
                 'MarkerFaceColor','y','MarkerSize',7);
            nTrading = nTrading + 1;
            buy = 0;
            sell = 0;
        end 
    end
    position_legend = [h1 h2 h3 h4 h5 h6 h7 h8];
    r_excess = mean(rBuy(isnan(rBuy)==0)) + mean(rSell(isnan(rSell)==0));
    r_excess_after_cost = r_excess - cost*r_excess;
    